/*
 * (c) Copyright Microsoft Corporation. 
 * This source is subject to the Microsoft Public License.
 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL       
 */
package com.microsoft.hsg;

/**
 * Translate a HealthVault response code into an enum
 * and exception class.
 */
public class DefaultResponseCodeTranslator
{
	
	/**
	 * Translate.
	 * 
	 * @param responseCode the response code
	 * 
	 * @return the exception
	 */
	public HVException translate(int responseCode)
	{
		StatusCode statusCode = StatusCode.parse(responseCode);
		switch(statusCode)
		{
		    case AUTHENTICATED_SESSION_TOKEN_EXPIRED:
		    	return new HVApplicationSessionExpiredException(statusCode);
		    case CREDENTIAL_TOKEN_EXPIRED:
		    	return new HVUserTokenExpiredException(statusCode);
		    case ACCESS_DENIED:
		    	return new HVAccessDeniedException(statusCode);
		}
		return new HVUncategorizedException(statusCode, responseCode);
	}
}
